
#include "BrushMonsMgr.h"



BrushMonsMgr::BrushMonsMgr() :m_pCommonPool(nullptr), m_pTowerPool(nullptr), m_pGuardPool(nullptr), m_pEmptyPool(nullptr), m_pGuidePool(nullptr)
{

}

BrushMonsMgr::~BrushMonsMgr()
{

}

bool BrushMonsMgr::Init()
{
	m_pCommonPool = new ObjectPool<BrushCommon>(20, false);
	MMO_ASSERT(nullptr != m_pCommonPool);
	m_pTowerPool = new ObjectPool<BrushTower>(20, false);
	MMO_ASSERT(nullptr != m_pTowerPool);
	m_pGuardPool = new ObjectPool<BrushGuard>(20, false);
	MMO_ASSERT(nullptr != m_pGuardPool);
	m_pEmptyPool = new ObjectPool<BrushEmpty>(20, false);
	MMO_ASSERT(nullptr != m_pEmptyPool);
	m_pUnionPool = new ObjectPool<BrushUnion>(20, false);
	MMO_ASSERT(nullptr != m_pUnionPool);
	m_pGuidePool = new ObjectPool<BrushGuide>(20, false);
	MMO_ASSERT(nullptr != m_pGuidePool);

	
	return true;
}


void BrushMonsMgr::UnInit()
{

	MMO_DELETE(m_pCommonPool);
	MMO_DELETE(m_pTowerPool);
	MMO_DELETE(m_pGuardPool);
	MMO_DELETE(m_pEmptyPool);
	MMO_DELETE(m_pUnionPool);
	MMO_DELETE(m_pGuidePool);	
}

void BrushMonsMgr::RecycleBrush(IBrushMonster *pBrushObj)
{
	if (nullptr != pBrushObj)
	{
		pBrushObj->UnInit();
		FreeBrushObj(pBrushObj);
	}
}

IBrushMonster *BrushMonsMgr::MakeBrushObj(int8_t byBrushType)
{
	IBrushMonster *pBrushObj = nullptr;
	switch (byBrushType)
	{
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Common:
		{
			pBrushObj = (IBrushMonster*)m_pCommonPool->MallocObj();
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Tower:
		{
			pBrushObj = (IBrushMonster*)m_pTowerPool->MallocObj();
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Guard:
		{
			pBrushObj = (IBrushMonster*)m_pGuardPool->MallocObj();
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Emputy:
		{
			pBrushObj = (IBrushMonster*)m_pEmptyPool->MallocObj();
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Union:
		{
			pBrushObj = (IBrushMonster*)m_pUnionPool->MallocObj();
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Guide:
		{
			pBrushObj = (IBrushMonster*)m_pGuidePool->MallocObj();
		}
	break;
	default:
		break;
	}
	return pBrushObj;
}

void BrushMonsMgr::FreeBrushObj(IBrushMonster *pBrushObj)
{
	int8_t byBrushType = pBrushObj->GetBrushType();
	switch (byBrushType)
	{
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Common:
		{
			m_pCommonPool->FreeObj((BrushCommon*)pBrushObj);
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Tower:
		{
			m_pTowerPool->FreeObj((BrushTower*)pBrushObj);
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Guard:
		{
			m_pGuardPool->FreeObj((BrushGuard*)pBrushObj);
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Emputy:
		{
			m_pEmptyPool->FreeObj((BrushEmpty*)pBrushObj);
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Union:
		{
			m_pUnionPool->FreeObj((BrushUnion*)pBrushObj);
		}
		break;
	case (int8_t)EDuplicateBrushType::EDuplicateBrushType_Guide:
		{
			m_pGuidePool->FreeObj((BrushGuide*)pBrushObj);
		}
	break;
	default:
		{
			MMO_DELETE(pBrushObj);
			LogErrFmtPrint("[logic] BrushMonsMgr::FreeBrushObj...unkonwn brush monster type ....byBrushType:%d ", byBrushType);
		}
		break;
	}
}